package jdbc;

import java.sql.*;

/**
 * Created by Administrator on 2017/9/11.
 */
public class ConnectionTest {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
     /*   //加载驱动名称
        Class.forName("com.mysql.jdbc.Driver");
        //下面三个参数分别指的是路径 用户名 密码
        Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3307/usea","root","123456");*/
             Connection conn =  ConnectionUtils.getConnection();
        if(conn != null){
            System.out.println("长的帅");
        }
        else
        {
            System.out.println("长的丑");
        }
        //connection无法用于查询 需要使用statement
        Statement statement= conn.createStatement();
        String sql ="select * from myname";
        ResultSet set =statement.executeQuery(sql);//执行查询
        while (set.next()){
            //打印出查询结果 getString的参数为字段数目
         //   System.out.println(set.getString(1)+","+set.getString(2));
            Myname myname= new Myname();
            myname.setName(set.getString(1));
            myname.setId(set.getInt(2));
            myname.setCat(set.getString(3));
        }
        set.close();
    }
}
